<?php
include_once dirname(__FILE__)."/../../model/config.php";
		$_diplome=new diplome();
if(isset($_POST["operation"])){
if($_POST["operation"]=="INSERT"){
		if(isset($_POST["CODE_DIPLOME"])){$_diplome->set_CODE_DIPLOME($_POST["CODE_DIPLOME"]);}
		if(isset($_POST["LIBELLE_DIPLOME"])){$_diplome->set_LIBELLE_DIPLOME($_POST["LIBELLE_DIPLOME"]);}
		$res=$_diplome->INSERT(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}
elseif($_POST["operation"]=="DELETE"){
		if(isset($_POST["CODE_DIPLOME"])){
		$_diplome->set_CODE_DIPLOME($_POST["CODE_DIPLOME"]);
		$res=$_diplome->DELETE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
		}
}
elseif($_POST["operation"]=="UPDATE"){
		if(isset($_POST["CODE_DIPLOME"])){$_diplome->set_CODE_DIPLOME($_POST["CODE_DIPLOME"]);}
		if(isset($_POST["LIBELLE_DIPLOME"])){$_diplome->set_LIBELLE_DIPLOME($_POST["LIBELLE_DIPLOME"]);}
		$res=$_diplome->UPDATE(); 

	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('success' => 'true','result' => "$res" ));
	  	
	  }
}

}
else{
	$constraint='';$limit=0;$start=0;$pagination='';
	if(isset($_POST["CODE_DIPLOME"]) && !empty($_POST["CODE_DIPLOME"])){
		$constraint.=" AND CODE_DIPLOME='".$_POST["CODE_DIPLOME"]."'";
	}

	if(isset($_POST["LIBELLE_DIPLOME"]) && !empty($_POST["LIBELLE_DIPLOME"])){
		$constraint.=" AND LIBELLE_DIPLOME='".$_POST["LIBELLE_DIPLOME"]."'";
	}

	if(isset($_POST['limit'])){$limit=$_POST['limit'];}
	if(isset($_POST['start'])){$start=$_POST['start'];}
	if($limit>0){
		$pagination.=" LIMIT  $start,$limit"; 
}
		$res=$_diplome->SELECT($constraint,$pagination); 

		 $data=array();
		  while($row=$_diplome->fetch_object()){
		  	$data[]=$row;
	  	  }
  	 	 
		
	   if($res!="success"){
		echo json_encode(array('success' => 'false','result' => "$res" ));
	  }else{
	  	echo json_encode(array('totalcount' => count($data),'result' => $data ));
	  	
	  }}
?>